package com.yingside.gui;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class TestJListFrame extends JFrame {
    private JList jList;
    private JScrollPane scrollPane;
    public TestJListFrame() {
        this.setTitle("下拉菜单窗口");
        this.setBounds(300, 300, 400, 400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Student s1 = new Student(1,"小刘","213123211");
        Student s2 = new Student(2,"小张","213123212");
        Student s3 = new Student(3,"小关","213123213");
        Student s4 = new Student(4,"小曹","213123214");
        /*
        List<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);*/

//        Student [] stus = {s1,s2,s3,s4};
//        jList = new JList(stus);

        jList = new JList();
        DefaultListModel model = new DefaultListModel();
        model.addElement(s1);
        model.addElement(s2);
        model.addElement(s3);
        model.addElement(s4);

        jList.setModel(model);

        jList.setFixedCellWidth(100);
        jList.setFixedCellHeight(40);

        scrollPane = new JScrollPane(jList);
        this.add(scrollPane, BorderLayout.WEST);

    }

    public static void main(String[] args) {
        TestJListFrame jListFrame = new TestJListFrame();
        jListFrame.setVisible(true);
    }
}
